﻿using System;
using System.Windows.Media;
using VNet.VisiSuite.Common.Helpers;
using VNet.VisiSuite.VisiBoard.BusinessLogic;
using VNet.VisiSuite.VisiBoard.Common.Helpers;

namespace VNet.VisiSuite.VisiBoard.Models
{
    public class ProductionModel : BaseModel
    {

        private static BusinessLogic.VisiBoard _visi_board = null;
        public ProductionModel()
        {
            _visi_board = BusinessLogic.VisiBoard.instance();
        }

        public VNet.VisiSuite.VisiBoard.BusinessLogic.LocalUtil.ProductionData productionMeterData()
        {
            var data = LocalUtil.productionMeterData(_visi_board.CellShiftId, _visi_board.AreaId, _visi_board.ShiftStart, _visi_board.ShiftEnd, _visi_board.ProductionMeterWidth);
            data.ProductionMeterFreq = _visi_board.ProductionMeterLabelFreq;
            if (data.Axis != null)
            {
                int i = 0;
                foreach (var ax in data.Axis)
                {
                    ax.Index = i;
                    i++;
                }
            }
            return data;
        }
        
        public bool IsMachineRunning
        {
            get { return _visi_board.IsMachineRunning; }
        }

        public bool IsLoadUnloadOverrun
        {
            get { return _visi_board.IsLoadUnloadOverrun; }
        }

        public string DowntimeDescription
        {
            get { return _visi_board.DowntimeReasonDesc; }
        }

        public DateTime DowntimeSince
        {
            get { return _visi_board.DowntimeReasonSince; }
        }

        public Brush DowntimeForeground
        {
            get { return new SolidColorBrush(ColorHelper.StringToColor(_visi_board.DowntimeRollupForeground, Colors.White)); }
        }

        public Brush DowntimeBackground
        {
            get { return new SolidColorBrush(ColorHelper.StringToColor(_visi_board.DowntimeRollupBackground, Colors.Red)); }
        }

        public Brush HeaderForeground
        {
            get { return DowntimeForeground; }
        }

        public Brush HeaderBackground
        {
            get
            {
                return DowntimeBackground;
                /**
                Brush brush;
                string fg, bg;
                if (_visi_board.alarmColors(100, _visi_board.IsMachineRunning, out fg, out bg))
                    brush = new SolidColorBrush(ColorHelper.StringToColor(bg, Colors.Red));
                else
                    brush = new SolidColorBrush(Colors.Red);
                return brush;
                 * **/
            }
        }
        
    }
}
